package com.practice.concurrency.signal;

public class ThreadSignal {

	class MonitorObject {
		
	}
	
	private MonitorObject monitorObject = new MonitorObject();
	
	public void doWait() {
		synchronized (monitorObject) {
			String threadName = Thread.currentThread().getName();
			try {
				System.out.println(threadName + " is waiting.");
				monitorObject.wait();
				System.out.println(threadName + " wakes up.");
			} catch (InterruptedException ex) {
				ex.printStackTrace();
			}
		}
	}
	
	public void doNotify() {
		synchronized (monitorObject) {
			String threadName = Thread.currentThread().getName();
			System.out.println(threadName + " will wake up a waiting thread.");
			monitorObject.notify();
		}
	}
}
